//
//  DDPopResultVC.m
//  dingdang
//
//  Created by 阮 沧晖 on 15/7/4.
//  Copyright (c) 2015年 阮 沧晖. All rights reserved.
//

#import "DDPopResultVC.h"

@interface DDPopResultVC ()

@property (weak, nonatomic) IBOutlet UITextField *nameTF;
@property (weak, nonatomic) IBOutlet UITextField *schoolTF;
@property (weak, nonatomic) IBOutlet UITextField *clzssTF;

@end

@implementation DDPopResultVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    [self createUI];
    [self createData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)createUI
{
    UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissPopup)];
    tapRecognizer.numberOfTapsRequired = 1;
    tapRecognizer.delegate = self;
    [self.view addGestureRecognizer:tapRecognizer];
}

-(void)createData
{
    DDSharedUser *sharedUser = [DDSharedUser shared];
    _nameTF.text = sharedUser.userInfo.name?sharedUser.userInfo.name:sharedUser.userInfo.nickName;
    _schoolTF.text = sharedUser.userInfo.school;
    _clzssTF.text = sharedUser.userInfo.clzss;
    
}
-(void)dismissPopup
{
    [_clzssTF resignFirstResponder];
    [_schoolTF resignFirstResponder];
    [_nameTF resignFirstResponder];
    [[NSNotificationCenter defaultCenter]  postNotificationName:@"dismissPopup" object:nil];
}
#pragma mark - UITextFieldDelegate
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
 
    if (textField == _nameTF) {
        [_schoolTF becomeFirstResponder];
    }
    if (textField == _schoolTF) {
        [_clzssTF becomeFirstResponder];
    }
    if (textField == _clzssTF) {
        [self submitAction:nil];
    }
    return YES;
}
- (IBAction)submitAction:(id)sender {
    if (_SubmitButtonBlock) {
        _SubmitButtonBlock(_nameTF.text,_schoolTF.text,_clzssTF.text);
    }
}
- (IBAction)cancelAction:(id)sender {
    if (_cancelPop) {
        _cancelPop();
    }
  // [[NSNotificationCenter defaultCenter]  postNotificationName:@"dismissPopup" object:nil];
}
@end
